/*
 * Book.java
 *
 * This class stores ISBN numbers in an array and provides methods to populate,
 * sort and display the array.
 *

 */

package com.javacore.day4.BooksISBN;

import java.util.Scanner;

/**
 * Book class stores information about the book ISBN in a one-dimensional array,
 * and displays the sorted array.
 *
 * @author SOn
 */
public class Book {
    
    /**
     * An array to store five ISBN numbers.
     */
    int isbn[];
    
    /** Creates a new instance of Book class */
    public Book() {
        isbn = new int[5];
    }
    
    /**
     * Method to populate the array isbn with five ISBN numbers.
     */
    void setIsbn() {
        Scanner input = new Scanner(System.in);
        
        System.out.println("Enter five ISBN numbers:");
        
        // Iterate until five ISBN numbers are accepted
        for(int index = 0;index < isbn.length;index++) {
            isbn[index] = input.nextInt();
        }
        
    }
    
    /**
     * Method to display the ISBN numbers stored in array isbn in
     * descending order.
     */
    void getIsbn() {
        
        // Display the ISBN numbers stored in the array
        for (int index = 0;index < isbn.length; index++)
            System.out.println(isbn[index]);
    }
    
    /**
     * Method to sort the ISBN numbers stored in array isbn.
     */
    void sortIsbn() {
        
        int temp;
        
        // Iterate until five ISBN numbers are sorted
        for(int j = 0;j < isbn.length;j++) {
            
            // Iterate to compare elements till the end of array
            for(int i = 0;i < 4;i++) {
                
                /* Check whether the next element is less than
                   the current element in the array */
                if (isbn[i] > isbn[i+1]) {
                    temp = isbn[i+1];
                    isbn[i+1] = isbn[i];
                    isbn[i] = temp;
                }
            }
        }
    }
}